from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

class infoPage:
    def __init__(self,driver):
        # self.driver=webdriver.Chrome()
        self.driver=driver

    setting_locator=(By.CLASS_NAME,'u-dt')
    userinfo_locator=(By.CSS_SELECTOR,'[class="u-dd"]:first-child')
    photo_locator=(By.ID,'preview')
    upload_frame_locator=(By.CSS_SELECTOR,'[id *=layui-layer-iframe]')
    file_locator=(By.CSS_SELECTOR,'[id="filePicker2"] [name="file"]')
    savebtn_locator=(By.CLASS_NAME,'saveBtn')
    upload_frame_locator=(By.CSS_SELECTOR,'[value="确认保存"]')

    def upload_user_photo(self,filepath):
        ActionChains(self.driver).move_to_element(self.driver.find_element(*self.setting_locator)).perform()
        self.driver.find_element(*self.userinfo_locator).click()
        self.driver.find_element(*self.photo_locator).click()
        frame=self.driver.find_element(*self.upload_frame_locator)
        self.driver.switch_to(frame)
        self.driver.find_element(*self.savebtn_locator).click()
        self.driver.switch_to.default_content()
        self.driver.find_element(*self.upload_success_locator).click()



















